﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.Windows.Forms;
using NetJsWire.JsonRpcHandler.Attributes;
using NetJsWire.Widgets.Core;
using NetJsWire.Widgets.Renderers.Core;

namespace NetJsWire.Widgets.Renderers.Form
{
    [ClassName( "Ext.form.FieldSet" )]
    internal class FieldSet : Widget
    {
        public FieldSet( object baseObject )
            : base( baseObject )
        {
        }

        public override void Render()
        {
            if ( !Rendered )
            {
                if ( BaseParent is IWidgetContainer )
                {
                    SetAttribute( ControlNode, "isInContainer", true );
                    SetConstructionProperty( "isInContainer", true );

                    SetConstructionProperty( "x", ( ( Control ) Base ).Left );
                    SetConstructionProperty( "y", ( ( Control ) Base ).Top );

                    SetConstructionProperty( "labelAlign", "top" );
                    SetConstructionProperty( "labelWidth", 75 );
                }
                else
                {
                    SetStyleProperty( "position", "absolute" );
                    SetConstructionProperty( "renderTo", ClientParentToRender );
                }
                EnsureParentNodePosition();

                SetAttribute( "isContainer", true );

                if ( !( ( Ui.Form.FieldSet ) Base ).AutoSize )
                {
                    SetConstructionProperty( "width", ( ( Ui.Form.FieldSet ) Base ).ClientSize.Width );
                    SetConstructionProperty( "height", ( ( Ui.Form.FieldSet ) Base ).ClientSize.Height );
                }
                else
                {
                    SetConstructionProperty( "autoWidth", true );
                    SetConstructionProperty( "autoHeight", true );
                }
                SetConstructionProperty( "title", ( ( Ui.Form.FieldSet ) Base ).Text );
                SetConstructionProperty( "layout", ( ( Ui.Form.FieldSet ) Base ).Layout.ToString().ToLower() );
                if ( ( ( Ui.Form.FieldSet ) Base ).CheckBoxToggle )
                    SetConstructionProperty( "checkboxToggle", true );
                if ( ( ( Ui.Form.FieldSet ) Base ).Collapsible )
                    SetConstructionProperty( "collapsible", true );
            }
            base.Render();
        }
    }
}